package leetcode.string;

import java.util.Arrays;

public class Leetcode_781 {
    public static void main(String[] args) {
        int res = new Leetcode_781().numRabbits(new int[]{1, 1, 2});
        System.out.println(res);
    }

    public int numRabbits(int[] answers) {
        Arrays.sort(answers);
        int n = answers.length;
        int ans = 0;
        for (int i = 0; i < n; i++) {
            int cnt = answers[i];
            ans += cnt + 1;
            // 跳过「数值 cnt」后面的 cnt 个「数值 cnt」
            int k = cnt;
            while (k-- > 0 && i + 1 < n && answers[i] == answers[i + 1])
                i++;
        }
        return ans;

    }
}
